package cn.exrick.xboot.modules.Information.serviceimpl;

import cn.exrick.xboot.modules.Information.dao.mapper.RiverTourHistoryMapper;
import cn.exrick.xboot.modules.Information.entity.RiverTourHistory;
import cn.exrick.xboot.modules.Information.service.IRiverTourHistoryService;
import cn.exrick.xboot.modules.activiti.entity.business.EventReport;
import cn.exrick.xboot.modules.activiti.entity.business.RiverAvg;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 巡河历史表接口实现
 * @author lijian
 */
@Slf4j
@Service
@Transactional
public class IRiverTourHistoryServiceImpl extends ServiceImpl<RiverTourHistoryMapper, RiverTourHistory> implements IRiverTourHistoryService {

    @Autowired
    private RiverTourHistoryMapper riverTourHistoryMapper;

    @Override
    public List<RiverTourHistory> queryRiverHistoryByDateAll(Map map) {
        return riverTourHistoryMapper.queryRiverHistoryByDateAll(map);
    }

    @Override
    public Integer findTimeAll() {
        return riverTourHistoryMapper.findTimeAll();
    }

    @Override
    public String findKmAll() {
        return riverTourHistoryMapper.findKmAll();
    }

    @Override
    public List<Map> findXcCharts() {
        return riverTourHistoryMapper.findXcCharts();
    }

    @Override
    public List<RiverTourHistory> getDateUserName(String userName , String date) {
        return riverTourHistoryMapper.getDateUserName(userName,date);
    }

    @Override
    public List<String> findEndTime() {
        return riverTourHistoryMapper.findEndTime();
    }

    @Override
    public int fingByIdUpdate(Map map) {
        return riverTourHistoryMapper.fingByIdUpdate(map);
    }
    @Override
    public List<RiverAvg> getCenterOne() {
        DecimalFormat format = new DecimalFormat("0.00");
        List<RiverAvg> avgList = new ArrayList<>();
        String avgAll= riverTourHistoryMapper.avgAll();
       String format1 = format.format(new BigDecimal(avgAll));
//          String substring = avgAll.substring(0,5);
        RiverAvg riverAvg1 = new RiverAvg();
        riverAvg1.setName("1");
        riverAvg1.setAge("巡河情况-全部河长");
        riverAvg1.setAddress(format1);
        avgList.add(riverAvg1);
        RiverAvg riverAvg3 = new RiverAvg();
        riverAvg3.setName("2");
        riverAvg3.setAge("巡河情况-村");
        String avgCun = riverTourHistoryMapper.avgCun();
        String format2 = "";
        if(avgCun!=null){
          format2 = format.format(new BigDecimal(avgCun));
        }else{
            format2 = "0";
        }
//         String avgCun2 = avgCun.substring(0,5);
        riverAvg3.setAddress(format2);
        avgList.add(riverAvg3);
        return avgList;
    }

    @Override
    public List<EventReport> findByAll() {
        return riverTourHistoryMapper.findByAll();
    }
}